import { ADMIN_TOKEN } from '~/utils/common'

export function setItem(key, value) {
  localStorage.setItem(key, JSON.stringify(value))
}

export function getItem(key) {
  const value = localStorage.getItem(key)
    try {
      return JSON.parse(value || '')
    } catch (error) {
      return value
    }
}

export function removeItem(key) {
  localStorage.removeItem(key)
}

export function clearAll() {
  localStorage.clear()
}


// 设置token
export function setToken(value) {
  localStorage.setItem(ADMIN_TOKEN, value)
}

// 得到token
export function getToken() {
  return localStorage.getItem(ADMIN_TOKEN) || ''
}

// 移除token
export function removeToken() {
  localStorage.removeItem(ADMIN_TOKEN)
}
